package com.sky.controller.admin;

import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.dto.SetmealDTO;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    @PostMapping
    @ApiOperation("套餐添加相关接口")
    public Result save(@RequestBody SetmealDTO setmealDTO) {
        log.info("套餐添加:{}");
        setmealService.save(setmealDTO);
        return Result.success();
    }

    @ApiOperation("套餐起售停售接口")
    @PostMapping("/status/{status}")
    public Result startorStop(@PathVariable Integer status, Long id) {
        log.info("套餐起售停售:{}");
        setmealService.startorStop(status, id);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("套餐分页查询接口")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQuery) {
        log.info("套餐分页查询:{}", setmealPageQuery);
        PageResult pageResult = setmealService.pageQuery(setmealPageQuery);

        return Result.success(pageResult);
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }


    @ApiOperation("批量删除接口")
    @DeleteMapping()
    public Result deleteByIds(@RequestParam List<Long> ids) {
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    @ApiOperation("修改套餐接口")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return Result.success();
    }
}
